home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14671 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: svnews.ubinet.ubs.com!ubszh!ian.johnston@ubs.com
  2. From: ian.johnston@ubs.com (Ian Johnston (by ubsswop))
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: C++ meta-problem
  5. Date: 1 Apr 1996 13:51:42 GMT
  6. Organization: UBS
  7. Distribution: world
  8. Message-ID: <4jon1e$ka@ubszh.fh.zh.ubs.com>
  9. References: <4jmtlg$smm@baskerville.CS.Arizona.EDU>
  10. NNTP-Posting-Host: nol2179.fh.zh.ubs.com
  11.  
  12. In article <4jmtlg$smm@baskerville.CS.Arizona.EDU>, kdb@CS.Arizona.EDU (Koen De Bosschere) writes:
  13. |> In order to prevent to write an iterator for every operation 
  14. |> I want to perform on a list, I tried to write a kind of 
  15. |> meta-iterator that would apply a particular method to 
  16. |> all listnodes. For some reason, I cannot execute a 
  17. |> function variable on an object. Does anyone has an
  18. |> idea how I can solve this problem?
  19.  
  20. [...]
  21.  
  22. |> void iterate(testclass *root, void (testclass::*f)())
  23. |> {
  24. |>   testclass *p = root;
  25. |>   while (p) { 
  26. |>     p->f();      //  <--- here the compiler generates an error (see below)
  27. |>     p = p->getnext();
  28. |>   }
  29. |> }
  30.  
  31.  
  32. To solve this problem, try
  33.  
  34.     p->*f();
  35.  
  36.  
  37. However, this is not a very general solution. You may want to look
  38. at function objects (as being discussed in another thread right now).
  39.  
  40. Ian
  41.  
  42.